package ph.gov.marikina.mcsmtms.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ph.gov.marikina.mcsmtms.dao.SettingsDAO;
import ph.gov.marikina.mcsmtms.domain.Settings;
import ph.gov.marikina.mcsmtms.domain.SituationReport;

@Transactional
@Repository
public class SettingsDAOImpl implements SettingsDAO {

	private SessionFactory sessionFactory;
	
	@Override
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Settings getSettings(Integer id) {
		Query query = this.sessionFactory.getCurrentSession()
                .createQuery("from Settings where id = :id");
		query.setParameter("id", id);
		
		return (Settings) query.uniqueResult();
	}
	
	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List<Settings> getAllSettings() {
		Query query = this.sessionFactory.getCurrentSession()
                .createQuery("from Settings");
		
		return (List<Settings>) query.list();
	}
}
